package thirdassigment;

import java.io.*;
//import java.util.*;

public class DirViewTree implements ICommandExecutor{
	private static ICommandExecutor instance;
	public void execute(String enterstr)
	{
		String[] str_mas = enterstr.split(" ");
		//String command = str_mas[0];
		String directory = str_mas[1];
	    //String SearchWord = str_mas[2];
		
	    File f = new File(directory);
	    if (f.isDirectory()) 
	    {  
	      System.out.println(directory);
	    
	      mylist(directory, "");
	      
	    }
	    
	}
	
	static void mylist(String Dir, String gap){
		
		File f = new File(Dir);
		String s[] = f.list();
		
		
		for(int i = 0; i < s.length; i++)
		{
		  File f1 = new File(Dir + "/" + s[i]);
		        
		  if(f1.isDirectory()){
			  System.out.println(gap + "[+]" + s[i]);	  
		      mylist(Dir + "/" + s[i], gap + " ");
		    
		  }else 
			  System.out.println(gap + s[i]);
		 
		}
		
	}
	
	
	public static ICommandExecutor getInstance() {
        if(instance==null){
                instance=new DirViewTree();       
                }
        return instance;
}
}
